package zip;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Zip {

	public static boolean unZip(String srcPath, String dstPath) {
		ZipFile zipFile = null;
		try {
			zipFile = new ZipFile(srcPath);
			Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zipFile
					.entries();
			while (entries.hasMoreElements()) {
				ZipEntry zipEntry = entries.nextElement();
				if (zipEntry.isDirectory()) {// 是文件夹
					continue;
				}

				File description = new File(dstPath, zipEntry.getName());
				if (!description.getParentFile().exists()) {
					description.getParentFile().mkdirs();
				}

				InputStream is = new BufferedInputStream(
						zipFile.getInputStream(zipEntry));
				OutputStream os = new BufferedOutputStream(
						new FileOutputStream(description));
				byte[] buffer = new byte[1024];
				int len = 0;
				while ((len = is.read(buffer)) != -1) {
					os.write(buffer, 0, len);
				}
				is.close();
				os.close();
				;
			}
			zipFile.close();
			return true;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public static void main (String args[]) {
		unZip("C:/Users/i/Desktop/1.zip", "D:/1111/");
	}
}
